package com.eling.elcms.travel.webapp.controller;

import com.eling.elcms.core.dao.hibernate.search.SearchCondition;
import com.eling.elcms.core.webapp.controller.BaseFormController;
import com.eling.elcms.core.webapp.controller.Msg;
import com.eling.elcms.core.webapp.spring.ModelFilling;
import com.eling.elcms.questionnaire.model.QuestionAnswerSheet;
import com.eling.elcms.travel.model.Customer;
import com.eling.elcms.travel.model.CustomerVisitRecord;
import com.eling.elcms.travel.service.ICustomerVisitRecordManager;
import com.eling.elcms.visit.model.view.QuestionAnswerSheetView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class CustomerVisitRecordController extends BaseFormController {

	@Autowired
	ICustomerVisitRecordManager cvrManager;

	@RequestMapping("/api/customervisitrecord/search*")
	@ResponseBody
	public List<CustomerVisitRecord> sreach(@ModelAttribute SearchCondition sc,
			@ModelAttribute CustomerVisitRecord cond) {
		sc.setQueryCondition(cond);
		return cvrManager.search(sc);
	}

	@RequestMapping("/api/customervisitrecord/query")
	@ResponseBody
	public List<CustomerVisitRecord> query(@ModelAttribute CustomerVisitRecord cond) {
		return cvrManager.query(cond);
	}

	@RequestMapping("/api/customervisitrecord/save")
	@ResponseBody
	public CustomerVisitRecord save(@ModelAttribute @ModelFilling CustomerVisitRecord cond) {
		return cvrManager.save(cond);
	}

	@RequestMapping("/api/customervisitrecord/{pkCustomerVisitRecord}/delete")
	@ResponseBody
	public Msg delete(@PathVariable Long pkCustomerVisitRecord) {
		cvrManager.remove(pkCustomerVisitRecord);
		return new Msg("删除成功");
	}

	/**
	 * 查询列表数据
	 * 
	 * @param cond
	 * @return
	 * @author zhoulin
	 */
	@RequestMapping("/api/customervisitrecord/queryall")
	@ResponseBody
	public List<CustomerVisitRecord> queryAll(@ModelAttribute CustomerVisitRecord cond) {
		return cvrManager.queryAll(cond);
	}

	/**
	 * 搜索列表数据
	 * 
	 * @param cond
	 * @return
	 * @author zhoulin
	 */
	@RequestMapping("/api/customervisitrecord/searchall")
	@ResponseBody
	public List<CustomerVisitRecord> searchAll(@ModelAttribute CustomerVisitRecord cond,
			@RequestParam(name = "str", required = false) String str) {
		return cvrManager.searchAll(cond, str);
	}

	/**
	 * 保存客户登记（来访/回访）
	 * 
	 * @param type
	 * @param customerVersion
	 * @param customer
	 * @param cvs
	 * @param questionAnswerSheet
	 * @param questionAnswerSheetView
	 * @return
	 * @author zhoulin
	 */
	@RequestMapping("/api/customervisitrecord/saveall")
	@ResponseBody
	public Msg saveAll(@RequestParam(name = "type", required = false) String type,
			@RequestParam(name = "customerVersion", required = false) Integer customerVersion,
			@ModelAttribute Customer customer, @ModelAttribute CustomerVisitRecord cvs,
			@ModelAttribute QuestionAnswerSheet questionAnswerSheet,
			@ModelAttribute QuestionAnswerSheetView questionAnswerSheetView) {
		return cvrManager.saveAll(type, customerVersion, customer, cvs, questionAnswerSheet, questionAnswerSheetView);
	}
	
	@RequestMapping("/api/customervisitrecord/savecontract")
	@ResponseBody
	public Msg saveContract(@RequestParam(name = "pkTravelContract", required = false) Long pkTravelContract,@ModelAttribute CustomerVisitRecord cvr,
			@ModelAttribute QuestionAnswerSheet questionAnswerSheet,
			@ModelAttribute QuestionAnswerSheetView questionAnswerSheetView) {
		return cvrManager.saveContract(pkTravelContract,cvr, questionAnswerSheet, questionAnswerSheetView);
	}

	/**
	 * 查询销售控制台提醒条数
	 * 
	 * @param cvr, type
	 * @return
	 * @author zhoulin
	 */
	@RequestMapping("/api/customervisitrecord/queryremind")
	@ResponseBody
	public Integer queryRemind(@ModelAttribute CustomerVisitRecord cvr,
			@RequestParam(name = "type", required = false) String type) {
		return cvrManager.queryRemind(cvr, type);
	}
	
}
